package com.fangshicai.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fangshicai.bean.User;
import com.fangshicai.service.UserService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName tableController
 * @Description TODO
 * @Author fangshicai
 * @Date 2021/7/16 20:10
 */
@Controller
public class tableController {

    @Autowired
    UserService userService;


    @GetMapping("/basic_table")
    public String basic_tablePage(){

        return "table/basic_table";
    }
    //{id}表示从前端获取的变量
    @GetMapping("/deleteUser/{id}")
    public String deleteUserById(@PathVariable("id") Integer id, @RequestParam(value = "pn",defaultValue = "1") Integer pn, RedirectAttributes re){
        userService.removeById(id);

        re.addAttribute("pn",pn);

        return "redirect:/dynamic_table";
    }

    @GetMapping("/dynamic_table")
    public String dynamic_tablePage(Model model, @RequestParam(value = "pn",defaultValue = "1") Integer pn){

//        List<User> lists = userService.list();
//        model.addAttribute("lists",lists);
//        for (User user : lists) {
//            System.out.println(user);
//        }
       Page<User> userPage= new Page<>(pn,2);
        Page<User> page = userService.page(userPage, null);
//        for (User record : page.getRecords()) {
//            System.out.println(record);
//        }
//        System.out.println("当前页码="+page.getCurrent());
//        System.out.println(page.getTotal());
//        System.out.println(page.getSize());
        model.addAttribute("page",page);

        return "table/dynamic_table";
    }
    @GetMapping("/editable_table")
    public String editable_tablePage(Model model){


//        model.addAttribute("users",Arrays.asList(new User("1","123"),
//                new User("2","1234"),
//                new User("3","1235")
//        ));

        return "table/editable_table";
    }
    @GetMapping("/pricing_table")
    public String pricing_tablePage(){

        return "table/pricing_table";
    }
    @GetMapping("/responsive_table")





    public String responsive_tablePage(){

        return "table/responsive_table";
    }
}
